#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(gcomm,0.1.0)
AC_CONFIG_HEADER([config.h])
AC_PREFIX_DEFAULT(/usr/local/)

# Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PATH_PROG(AR,ar,ar)

# Checks for libraries.
# FIXME: Replace `main' with a function in `-ldmallocth':
AC_CHECK_LIB([dmallocth], [main])
# FIXME: Replace `main' with a function in `-lpthread':
AC_CHECK_LIB([pthread], [main])

# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([libintl.h arpa/inet.h fcntl.h float.h inttypes.h limits.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/socket.h sys/time.h sys/timeb.h unistd.h wchar.h wctype.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_C_RESTRICT
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_C_VOLATILE
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_REPLACE_FNMATCH
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MKTIME
AC_FUNC_LSTAT
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_STRERROR_R
AC_FUNC_STRTOD
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([realpath gethostname gethostbyaddr alarm dup2 getcwd gethostbyname getpagesize gettimeofday localtime_r memmove memset mkdir munmap putenv regcomp rmdir select setenv socket sqrt strcasecmp strchr strdup strerror strncasecmp strrchr strspn strstr strtol strtoul strtoull tzset])

# enable code coverage
AC_ARG_ENABLE([codecoverage],
	[AC_HELP_STRING([--enable-codecoverage],
		[Turn on code coverage (default=disable)])],
	[CODE_COVERAGE=$enableval],
	[CODE_COVERAGE=no]
)

if test $CODE_COVERAGE = yes; then
	AC_MSG_RESULT([enable codecoverage])
else
	AC_MSG_RESULT([disable codecoverage])
fi

AC_SUBST(CODE_COVERAGE)

# enable debug
AC_MSG_CHECKING(for debug)
AC_ARG_ENABLE([debug],
	[AC_HELP_STRING([--enable-debug],
		[Turn off optimization flag and Turn on debug flag. (DEFINE _DEBUG)(default=disable)])],
	[DBG="$enableval"],
	[DBG=no]
)
if test x"$DBG" = xyes; then
	DBG=" -g "
else
	DBG=""
fi
AC_SUBST(DBG)


AC_CONFIG_FILES([./config.mk])
AC_OUTPUT
